from sqlalchemy import Column, Integer, String, Float, Boolean, Text, Date, DateTime, ForeignKey
from sqlalchemy.dialects.postgresql import BYTEA
# from sqlalchemy.orm import relationship

from .database import Base

class E2Img(Base):
    __tablename__ = "e2_img"
    
    img_id = Column(Integer, primary_key=True, index=True)
    img_filename = Column(String(1024), unique=True, nullable=True)
    img_modality = Column(String, nullable=True)
    img_mode = Column(String(255), nullable=True)
    img_acquisition_datetime = Column(DateTime, nullable=True)
    img_imported = Column(Boolean, nullable=True)
    img_kvp = Column(Float, nullable=True)
    img_ma = Column(Float, nullable=True)
    img_dose = Column(Float, nullable=True)
    img_note = Column(String(255), nullable=True)
    pat_id = Column(Integer, ForeignKey('e2_pat.pat_id'), nullable=True)
    pat_chartno = Column(String(255), nullable=True)
    img_raw_filename = Column(String(1024), nullable=True)
    img_update_datetime = Column(DateTime, nullable=True)
    img_modelname = Column(String(255), nullable=True)
    img_study_instance_uid = Column(String(255), nullable=True)
    rec_id = Column(Integer, nullable=True)
    img_exposure_time = Column(Float, nullable=True)
    img_comments = Column(Text, nullable=True)
    img_source_type = Column(String, default='Direct', nullable=True)
    img_source_id = Column(String(64), nullable=True)
    img_user_defined_1 = Column(Integer, nullable=True)
    img_user_defined_2 = Column(Integer, nullable=True)
    img_user_defined_3 = Column(Integer, nullable=True)
    img_user_defined_4 = Column(Float, nullable=True)
    img_user_defined_5 = Column(Float, nullable=True)
    img_user_defined_6 = Column(Boolean, nullable=True)
    img_user_defined_7 = Column(Boolean, nullable=True)
    img_user_defined_8 = Column(Boolean, nullable=True)
    img_user_defined_9 = Column(Text, nullable=True)
    img_user_defined_10 = Column(Text, nullable=True)
    img_user_defined_11 = Column(Text, nullable=True)
    img_user_defined_12 = Column(BYTEA, nullable=True)
    to_sended = Column(Boolean, default=False, nullable=True)

class E2Pat(Base):
    __tablename__ = "e2_pat"
    
    pat_id = Column(Integer, primary_key=True, index=True)
    pat_chartno = Column(String(255), unique=True, nullable=False)
    pat_lastname = Column(String(255), nullable=True)
    pat_firstname = Column(String(255), nullable=True)
    pat_middlename = Column(String(255), nullable=True)
    pat_gender = Column(String(2), nullable=True)
    pat_birthdate = Column(Date, nullable=True)
    pat_email = Column(String(255), nullable=True)
    pat_socialid = Column(String(255), nullable=True)
    pat_registered_datetime = Column(DateTime, nullable=True)
    pat_photo_filename = Column(String(1024), nullable=True)
    pat_chosung = Column(String(20), nullable=True)
    pat_note = Column(String(255), nullable=True)
    pat_phone = Column(String(64), nullable=True)
    pat_zipcode = Column(String(64), nullable=True)
    pat_address = Column(String(1024), nullable=True)
    pat_mobile = Column(String(64), nullable=True)
    pat_source_type = Column(String, default='Direct', nullable=True)
    pat_source_id = Column(String(64), nullable=True)
    pat_last_access = Column(DateTime, nullable=True)
    pat_user_defined_1 = Column(Integer, nullable=True)
    pat_user_defined_2 = Column(Integer, nullable=True)
    pat_user_defined_3 = Column(Float, nullable=True)
    pat_user_defined_4 = Column(Float, nullable=True)
    pat_user_defined_5 = Column(Boolean, nullable=True)
    pat_user_defined_6 = Column(Boolean, nullable=True)
    pat_user_defined_7 = Column(Text, nullable=True)
    pat_user_defined_8 = Column(Text, nullable=True)
    pat_user_defined_9 = Column(Text, nullable=True)
    pat_user_defined_10 = Column(BYTEA, nullable=True)